# Copyright 2022 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//bazel:psi.bzl", "psi_cc_binary", "psi_cc_library", "psi_cc_test")

package(default_visibility = ["//visibility:public"])

psi_cc_library(
    name = "communication",
    srcs = ["communication.cc"],
    hdrs = ["communication.h"],
    deps = [
        ":ic_protocol_psi_cc_proto",
        "//psi/psi/utils:serialize",
        "@yacl//yacl/base:exception",
        "@yacl//yacl/link",
    ],
)

cc_proto_library(
    name = "ic_protocol_psi_cc_proto",
    deps = ["@org_interconnection//interconnection/runtime:ecdh_psi"],
)

psi_cc_library(
    name = "ecdh_psi",
    srcs = ["ecdh_psi.cc"],
    hdrs = ["ecdh_psi.h"],
    deps = [
        ":communication",
        "//psi/psi:recovery",
        "//psi/psi/cryptor:cryptor_selector",
        "//psi/psi/utils:batch_provider",
        "//psi/psi/utils:ec_point_store",
        "@com_google_absl//absl/strings",
        "@yacl//yacl/link",
        "@yacl//yacl/utils:parallel",
    ],
)

psi_cc_test(
    name = "ecdh_psi_test",
    srcs = ["ecdh_psi_test.cc"],
    deps = [
        ":ecdh_psi",
        "//psi/psi/utils:test_utils",
    ],
)

psi_cc_binary(
    name = "ecdh_psi_bench",
    srcs = ["ecdh_psi_bench.cc"],
    deps = [
        ":ecdh_psi",
        "@com_github_google_benchmark//:benchmark_main",
    ],
)

psi_cc_library(
    name = "ecdh_3pc_psi",
    srcs = ["ecdh_3pc_psi.cc"],
    hdrs = ["ecdh_3pc_psi.h"],
    deps = [
        ":ecdh_psi",
    ],
)

psi_cc_test(
    name = "ecdh_3pc_psi_test",
    srcs = ["ecdh_3pc_psi_test.cc"],
    deps = [
        ":ecdh_3pc_psi",
        "//psi/psi/utils:test_utils",
    ],
)

psi_cc_binary(
    name = "ecdh_3pc_psi_bench",
    srcs = ["ecdh_3pc_psi_bench.cc"],
    deps = [
        ":ecdh_3pc_psi",
        "//psi/psi/utils:test_utils",
        "@com_github_google_benchmark//:benchmark_main",
    ],
)

psi_cc_library(
    name = "cuckoo_index",
    srcs = ["cuckoo_index.cc"],
    hdrs = ["cuckoo_index.h"],
    linkopts = ["-lm"],
    deps = [
        "@com_google_absl//absl/types:span",
        "@yacl//yacl/base:exception",
        "@yacl//yacl/base:int128",
    ],
)

psi_cc_test(
    name = "cuckoo_index_test",
    srcs = ["cuckoo_index_test.cc"],
    deps = [
        ":cuckoo_index",
        "@yacl//yacl/crypto/utils:rand",
    ],
)

psi_cc_library(
    name = "kkrt_psi",
    srcs = ["kkrt_psi.cc"],
    hdrs = ["kkrt_psi.h"],
    deps = [
        ":communication",
        ":cuckoo_index",
        "//psi/psi/utils:serialize",
        "@com_google_absl//absl/strings",
        "@yacl//yacl/crypto/base/hash:hash_utils",
        "@yacl//yacl/crypto/primitives/ot:base_ot",
        "@yacl//yacl/crypto/primitives/ot:iknp_ote",
        "@yacl//yacl/crypto/primitives/ot:kkrt_ote",
        "@yacl//yacl/crypto/utils:rand",
        "@yacl//yacl/link",
    ],
)

psi_cc_test(
    name = "kkrt_psi_test",
    srcs = ["kkrt_psi_test.cc"],
    deps = [
        ":kkrt_psi",
        "@yacl//yacl/crypto/base/hash:hash_utils",
    ],
)

psi_cc_binary(
    name = "kkrt_psi_bench",
    srcs = ["kkrt_psi_bench.cc"],
    deps = [
        ":kkrt_psi",
        "@com_github_google_benchmark//:benchmark_main",
    ],
)

psi_cc_library(
    name = "ecdh_oprf_psi",
    srcs = ["ecdh_oprf_psi.cc"],
    hdrs = ["ecdh_oprf_psi.h"],
    deps = [
        ":communication",
        "//psi/psi/core/ecdh_oprf:ecdh_oprf_selector",
        "//psi/psi/utils:batch_provider",
        "//psi/psi/utils:ec_point_store",
        "//psi/psi/utils:ub_psi_cache",
        "@com_google_absl//absl/strings",
        "@yacl//yacl/base:exception",
        "@yacl//yacl/link",
        "@yacl//yacl/utils:parallel",
    ],
)

psi_cc_test(
    name = "ecdh_oprf_psi_test",
    srcs = ["ecdh_oprf_psi_test.cc"],
    deps = [
        ":ecdh_oprf_psi",
        "//psi/psi/utils:test_utils",
        "@boost//:uuid",
        "@com_google_absl//absl/time",
        "@yacl//yacl/crypto/tools:prg",
        "@yacl//yacl/crypto/utils:rand",
        "@yacl//yacl/utils:scope_guard",
    ],
)

psi_cc_library(
    name = "mini_psi",
    srcs = ["mini_psi.cc"],
    hdrs = ["mini_psi.h"],
    defines = ["CURVE25519_DONNA"],
    deps = [
        ":communication",
        ":cuckoo_index",
        "//psi/psi/core/polynomial",
        "//psi/psi/utils:batch_provider",
        "//psi/psi/utils:serialize",
        "//psi/psi/utils:test_utils",
        "@com_github_floodyberry_curve25519_donna//:curve25519_donna",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest",
        "@yacl//yacl/crypto/base/hash:hash_utils",
        "@yacl//yacl/crypto/tools:prg",
        "@yacl//yacl/link",
        "@yacl//yacl/utils:parallel",
    ],
)

psi_cc_test(
    name = "mini_psi_test",
    srcs = ["mini_psi_test.cc"],
    deps = [
        ":mini_psi",
    ],
)

psi_cc_binary(
    name = "mini_psi_demo",
    srcs = ["mini_psi_demo.cc"],
    deps = [
        ":ecdh_psi",
        ":kkrt_psi",
        ":mini_psi",
    ],
)
